package cn.assumejson.springframework.common;

import cn.assumejson.springframework.beans.PropertyValue;
import cn.assumejson.springframework.beans.PropertyValues;
import cn.assumejson.springframework.beans.factory.BeansException;
import cn.assumejson.springframework.beans.factory.config.BeanDefinition;
import cn.assumejson.springframework.beans.factory.config.BeanFactoryPostProcessor;
import cn.assumejson.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * 测试 Spring BeanFactoryPostProcessor
 *
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/11/30 19:26
 */
@Slf4j
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        log.info("MyBeanFactoryPostProcessor is running ,this beanFactory is :{}", beanFactory);
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition("userService");
        PropertyValues propertyValues = beanDefinition.getPropertyValues();

        propertyValues.addPropertyValue(new PropertyValue("company", "改为：字节跳动"));
    }
}
